<?php
namespace app\common\exception;

use think\exception\HttpResponseException;

class NormalException extends HttpResponseException
{
    public function __construct($message = '服务器异常', $code = 500)
    {
        if (request()->type() === 'json') {
            $response = json([
                'message' => $message
            ], $code);
        } else {
            $body = '<h1>Oh no!</h1><p>发生错误：</p><p style="color: red;">' . $message . '</p>';
            $footer = '<p style="font-size: 0.7em">Copyright &copy; 2018-2019 DDLTECH.All rights reserved.<a href="http://sn.beian.miit.gov.cn" class="noselect">陕ICP备18011800号.</a></p>';
            $response = response($body . $footer);
        }

        parent::__construct($response);

        $this->message = $message;
        $this->code = $code;
    }
}
